package stu.day39_day.day41;

public class hw1 {

    public int minCost(int[][] costs) {

        int m = costs.length;
        int n = costs[0].length;

        int[][] dp = new int[m][n];

        for (int i=0;i<n;i++){
            dp[0][i] = costs[0][i];
        }

        for (int i=1;i<m;i++){
            dp[i][0] = Math.min(dp[i-1][1],dp[i-1][2])+costs[i][0];
            dp[i][1] = Math.min(dp[i-1][0],dp[i-1][2])+costs[i][1];
            dp[i][2] = Math.min(dp[i-1][1],dp[i-1][0])+costs[i][2];
        }

        int min = Integer.MAX_VALUE;
        for (int i=0;i<n;i++){
            min = Math.min(min,dp[m-1][i]);
        }

        return min;







    }


}
